from exts import db
from datetime import datetime
from datetime import date

class UserModel(db.Model):
    __table__name__ = "user_model"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(100), unique=True, nullable=False)
    password = db.Column(db.String(500), nullable=False)
    # email = db.Column(db.String(100), nullable=True, unique=True)
    # wechat = db.Column(db.String(100), nullable=True, unique=True)

    # objects = db.relationship('ObjectModel', backref='usermodel')

class ObjectModel(db.Model):
    __table__name__ = "object_model"
    object_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    objectname = db.Column(db.String(100), nullable=False)
    count = db.Column(db.Integer, default=1)
    classfication = db.Column(db.String(100), nullable=False)
    price = db.Column(db.Integer, nullable=True)
    maturity_time = db.Column(db.Date, nullable=False)
    picture = db.Column(db.String(100), nullable=True)
    place = db.Column(db.String(100), nullable=True)
    remarks = db.Column(db.Text, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))
    UserModel = db.relationship('UserModel', backref='objects')


    # 外键
    # user_id = db.Column(db.Integer, db.ForeignKey('usermodel.id'), nullable=True)
    # Usermodel = db.relationship(Usermodel, backref='user')

class HistoryModel(db.Model):
    __table__name__ = "history_model"
    object_id = db.Column(db.Integer, primary_key=True)
    objectname = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))
    UserModel = db.relationship('UserModel', backref='history_search')


    # 关系
    # objects = db.relationship(UserModel, backref="user")


    #关系
    # question = db.relationship(QuestionModel, backref = db.backref("answer", order_by = creat_time.desc()))
    # author = db.relationship(UserModel, backref = "answer")